//
//  TempFunExt.swift
//  ANOASTORE
//
//  Created by 邱仙凯 on 2024/1/30.
//  Copyright © 2024 zwb. All rights reserved.
//

import UIKit

// MARK: 封装逻辑
extension ConfigMenuForm {
    
    // 活跃细表 只开一个细表，当前活跃的细表   indexx 需要活跃的索引     status  开或关
    func activeDetailRow(indexx:Int,status:String,scroll:Bool = true) {
        guard self.detHandler[self.cDIndex].count > indexx else {return}
        if status == TRUE {
            // 把目前开的关了
            for i in 0..<self.detHandler[self.cDIndex].count {
                if any2Str(self.detHandler[self.cDIndex][i].dic[TKey.openx]) == TRUE {
                    self.detHandler[self.cDIndex][i].dic[TKey.openx] = "false"
                    //                    let set = IndexSet(integer:i)
                    //                    self.tableVw.reloadSections(set, with:UITableView.RowAnimation.automatic)
                }
                
            }
            self.detHandler[self.cDIndex][indexx].dic[TKey.openx] = status
            self.tableVw.reloadData()
            
            
               
            if scroll {
                self.tableVw.scrollToRow(at: IndexPath(row: 0, section: indexx), at: .bottom, animated: true)
            }
           
        } else {
            self.detHandler[self.cDIndex][indexx].dic[TKey.openx] = status
            let set = IndexSet(integer:indexx)
            self.tableVw.reloadSections(set, with:UITableView.RowAnimation.automatic)
            
        }
        
        
        
        
    }
    
    
 
    // 是否可操作细表具体逻辑
    func isOpeDetail(isOpFlag:String) -> Bool {
//        var isOpFlag = self.rootTemp.is_operation_detail
        
//        if self.detailsMode.count == detMCount {
//            isOpFlag = self.detailsMode[2]
//        }
        
        if self.excuteType == .add && (isOpFlag == "1" || isOpFlag == "2") {
            return true
        } else if self.excuteType == .fix && isOpFlag == "1" {
            return true
        } else {
            return false
        }
        
    }
    
    
    
    
}
